<?php

namespace app\queue\stomp;

use app\queue\BaseConsumer;
use common\service\MessageService;
use common\service\SupplierService;
use Webman\Stomp\RetryAbleConsumer;

class BatchSendSystemNoticeMessageConsumer extends BaseConsumer implements RetryAbleConsumer
{

    // 要消费的队列名
    public $queue = 'batch_send_system_notice_message';

    // 连接名，对应 config/redis_queue.php 里的连接`
    public $connection = 'default';

    /**
     * 处理事件
     * @param $data
     * @return mixed|void
     * @throws \Throwable
     * @throws \think\Exception
     */
    public function doConsume($data)
    {
        try {
            MessageService::getInstance()->batchSendSystemNoticeMessage($data['data'],$data['message_detail_data'],$data['notify_user_mark']);
        } catch (\Throwable $e) {
            trace(format_exception_info($e), 'ERR');
            throw $e;
        }
    }

    /**
     * 重试间隔
     * @return int
     */
    public function getTtr()
    {
        return 30;
    }

    /**
     * 能否重试判断
     * @param int $attempt
     * @param \Exception|\Throwable $error
     * @return bool
     */
    public function canRetry($attempt, $error)
    {
        return $attempt < 3;
    }
}
